<html>
<head><meta charset="utf-8"><title>docs: proc macro in expression · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/docs.3A.20proc.20macro.20in.20expression.html">docs: proc macro in expression</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="205177892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/docs%3A%20proc%20macro%20in%20expression/near/205177892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/docs.3A.20proc.20macro.20in.20expression.html#205177892">(Jul 27 2020 at 22:50)</a>:</h4>
<p>The <a href="https://doc.rust-lang.org/reference/procedural-macros.html#function-like-procedural-macros">documentation</a> on function-like procedural macros in the Rust reference says that they can't be used in expression position (the emphasis is mine):</p>
<blockquote>
<p>Function-like procedural macros may expand to a type or any number of items, including macro_rules definitions. They may be invoked in a type expression, item position (except as a statement), including items in extern blocks, inherent and trait implementations, and trait definitions. <strong>They cannot be used in a statement, expression, or pattern.</strong></p>
</blockquote>
<p>Yet it seems that I can do <code>println!("{}", my_proc_macro!())</code> on stable Rust. It seems that <a href="https://github.com/rust-lang/rust/issues/68717">#68717</a> introduced this. Is the reference out of date or am I missing something?</p>



<a name="205177944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/docs%3A%20proc%20macro%20in%20expression/near/205177944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark Drobnak <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/docs.3A.20proc.20macro.20in.20expression.html#205177944">(Jul 27 2020 at 22:51)</a>:</h4>
<p>It was just stabilized in 1.45 (July 16):<br>
<a href="https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html">https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html</a></p>
<p>The docs are likely out of date.</p>



<a name="205185119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/docs%3A%20proc%20macro%20in%20expression/near/205185119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/docs.3A.20proc.20macro.20in.20expression.html#205185119">(Jul 28 2020 at 00:36)</a>:</h4>
<p>The reference often lags behind <code>rustc</code> releases.  It was updated, but missed the branch window by a few days. The beta/nightly docs should be up-to-date (<a href="https://doc.rust-lang.org/nightly/reference/procedural-macros.html#function-like-procedural-macros">https://doc.rust-lang.org/nightly/reference/procedural-macros.html#function-like-procedural-macros</a>).</p>



<a name="205185253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/docs%3A%20proc%20macro%20in%20expression/near/205185253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/docs.3A.20proc.20macro.20in.20expression.html#205185253">(Jul 28 2020 at 00:38)</a>:</h4>
<p><span class="user-mention" data-user-id="120518">@Eric Huss</span> Thanks! I didn't realize that the reference branches like the compiler - I thought it was instantly deployed like the dev guide. I'll close the issue I filed (<a href="https://github.com/rust-lang/reference/issues/856">rust-lang/reference#856</a>)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>